home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / docs / misc / ConcNews.lha / news / amiga.compilers / comp.sys.amiga.programmer_32000_000031.msg < prev    next >
Encoding:
Text File  |  1994-11-27  |  9.7 KB  |  187 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: news.chalmers.se!sunic!EU.net!howland.reston.ans.net!gatech!concert!sas!mozart.unx.sas.com!walker
  3. From: walker@twix.unx.sas.com (Doug Walker)
  4. Subject: Re: Hello World lives on!
  5. Originator: walker@twix.unx.sas.com
  6. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  7. Message-ID: <CpozDt.F60@unx.sas.com>
  8. Date: Thu, 12 May 1994 13:41:52 GMT
  9. References:  <Evan_Hillas.dqk9@equinox.gen.nz>
  10. Nntp-Posting-Host: twix.unx.sas.com
  11. Organization: SAS Institute Inc.
  12. Lines: 173
  13.  
  14.  
  15. In article <Evan_Hillas.dqk9@equinox.gen.nz>, Evan_Hillas@equinox.gen.nz (Evan) writes:
  16. |> The following posting is a continuation of a local happening.
  17. |> 
  18. |> 
  19. |> Jayson_Mackie@equinox.gen.nz wrote:
  20. |> > This is just a little demo of how to open a screen and a window, then
  21. |> > send some graphical output to it.  It doesn't use any of the window flags
  22. |> > [...]
  23. |> 
  24. |> Here's my two cents worth:  I decided to make it as small as possible
  25. |> without dropping to assembly - with the following results.
  26. |> 
  27. |> Intui_Hello.c     A modified version of Jayson's "HelloWorld.intuition.c"
  28. |>                   This gave me a reduced executable size of 2360 bytes.
  29. |> 
  30. |> Intui_Hello3.c    A rewrite using NOSTARTUP.  This reduced the executable
  31. |>                   a further 900 bytes or so.  But about 600 bytes of c.o or
  32. |>                   sc.lib was still getting linked into the executable and
  33. |>                   of course not used.  So I cut it out with a hex editor:-)
  34. |> 
  35. |> Intui_Hello3.exe  Size, 884 bytes.  Only run from shell!!!
  36. |>                   Compiled with SAS/C 6.51
  37. |> 
  38. |> SCOPTIONS         The option file used to compile Intui_Hello3.c
  39. |>                   To use with "Intui_Hello.c" just remove NOSTARTUP
  40. |> 
  41. |> 
  42. |> PS: The chunk of executable I removed was auto-lib-init code.  Is it the
  43. |> norm for SAS/C to add it in no matter what, or have I missed something?
  44. |> 
  45.  
  46. SAS/C won't link in anything that you don't tell it to.  I tried your code
  47. with the MAP MAPHUNK MAPXREF options, and discovered that you were linking in
  48. autoinit code for the Intuition, Graphics, and DOS libraries (even though it
  49. was never called).  Why?  Because you weren't declaring IntuitionBase,
  50. GfxBase, and DOSBase.  Instead, you pulled their definitions in from the
  51. library.
  52.  
  53. If you pull them in from the library, you also get the autoinit code.
  54.  
  55. Moral: If you're not using a startup that calls __fpinit() and __fpterm(),
  56. make sure to define all your library bases explicitly.
  57.  
  58. (By the way, I got your example down to 748 bytes by defining those library
  59. bases.)
  60.  
  61. Here's detail on how to figure this out.  The linker map file is VERY 
  62. useful when you want to figure out how to get rid of unneeded stuff, BTW.
  63.  
  64. I compiled with MAP MAPHUNK MAPXREF and some formatting options and got 
  65. this map file:
  66.  
  67. =====================
  68. 4 09:23:Page 1-1
  69.  
  70.  num hunk         size filename         punit            type         base  alv     size
  71.    0 text          4b4 Intui_Hello3.o   Intui_Hello3.c   code            0    0      264
  72.                        LIB:sc.lib       _construct.c     code          264    0       34
  73.                        LIB:sc.lib       dummy.c          code          298    0        4
  74.                        LIB:sc.lib       autoopenfail.c   code          29c    0       fc
  75.                        LIB:sc.lib       doslib.c         code          398    0       5c
  76.                        LIB:sc.lib       gfxlib.c         code          3f4    0       60
  77.                        LIB:sc.lib       intuitlib.c      code          454    0       60
  78.    1 __MERGED       90 Intui_Hello3.o   Intui_Hello3.c   data            0    0       30
  79.                        T:3JQM5.0000     _ctdt.o          data           30    0       24
  80.                        LIB:sc.lib       _construct.c     data           54    0        4
  81.                        LIB:sc.lib       _stdwin.c        data           58    0       14
  82.                        LIB:sc.lib       wbmsg.c          bss            6c    0        4
  83.                        LIB:sc.lib       _construct.c     bss            70    0        4
  84.                        LIB:sc.lib       oslibversion.c   bss            74    0        4
  85.                        LIB:sc.lib       doslib.c         bss            78    0        8
  86.                        LIB:sc.lib       gfxlib.c         bss            80    0        8
  87.                        LIB:sc.lib       intuitlib.c      bss            88    0        8
  88.  
  89. 4 09:23:Page 3-1
  90.  
  91. symbol                   (Def) Module  Off
  92. @__autoopenfail  autoopenfail.c          0 intuitlib.c            22
  93.                                            gfxlib.c               22
  94.                                            doslib.c               22
  95. _DOSBase         doslib.c                0 Intui_Hello3.c         1c
  96.                                            Intui_Hello3.c         bc
  97.                                            Intui_Hello3.c        100
  98. _GfxBase         gfxlib.c                0 Intui_Hello3.c         40
  99.                                            Intui_Hello3.c         8c
  100.                                            Intui_Hello3.c         e0
  101. _IntuitionBase   intuitlib.c             0 Intui_Hello3.c         2e
  102.                                            Intui_Hello3.c         4c
  103.                                            Intui_Hello3.c         c6
  104.                                            Intui_Hello3.c         d4
  105.                                            Intui_Hello3.c         f0
  106. _LinkerDB              (0:*)               Intui_Hello3.c          6
  107. __STD_110_closed doslib.c               3a _ctdt.o                14
  108. __STD_110_closeg gfxlib.c               40 _ctdt.o                1c
  109. __STD_110_closei intuitlib.c            40 _ctdt.o                18
  110. __STI_110_opendo doslib.c                0 _ctdt.o                 c
  111. __STI_110_opengf gfxlib.c                0 _ctdt.o                 4
  112. __STI_110_openin intuitlib.c             0 _ctdt.o                 8
  113. __WBenchMsg      wbmsg.c                 0 autoopenfail.c         1c
  114.                                            autoopenfail.c         98
  115. ___construct     _construct.c            0 _ctdt.o                 0
  116. ___ctors         _ctdt.o                 4 _construct.c            0
  117. ___oslibversion  oslibversion.c          0 intuitlib.c             8
  118.                                            gfxlib.c                8
  119.                                            doslib.c                8
  120.                                            autoopenfail.c         46
  121. ___stdiowin      _stdwin.c               0 autoopenfail.c         2a
  122. =====================
  123.  
  124. (Note: In the XRef section (page 2), column 1 is the name of the symbol
  125. being defined; column 2 is the name of the module it is defined in;
  126. column 3 is the offset within that module; and the other module-offset
  127. pairs are the locations that refer to the symbol.)
  128.  
  129. One thing that jumps out right away from looking at the Xref section is the 
  130. autoinit and autoterm routines (the ones starting with __STD and __STI).
  131. We don't need 'em, we don't want 'em, let's get rid of 'em.  The Xref 
  132. section tells us they are defined in doslib.c, gfxlib.c, and intuitlib.c.
  133. These are files in sc.lib.  What are these files doing in our program?
  134. Time to go back to the Xref.
  135.  
  136. Other than the _STD and _STI routines, the only stuff defined in these
  137. three files are _DOSBase, _GfxBase, and _IntuitionBase.  These symbols
  138. are referred to from Intui_Hello3.c in several places.  Therefore,
  139. the linker pulled in doslib.c, gfxlib.c, and intuitlib.c in order to
  140. satisfy those references, and got the _STD and _STI routines because
  141. they were in the same module.
  142.  
  143. OK, so far so good.  The logical leap that you have to make is to accept
  144. the fact that the linker does some "magic".  If the linker sees at least
  145. one _STI or _STD routine, it creates and links in a file called _ctdt.o,
  146. which contains setup information that allows the startup to work on
  147. autoinit/autoterm routines.  As you can see from the Xref, almost everything
  148. else linked in was linked in because _ctdt.o was there.  Therefore, if you
  149. get rid of the _STI and _STD routines, you're home free.
  150.  
  151. I declared these three library bases in the .c file and the executable turned
  152. out to be 748 bytes, and produced this map:
  153.  
  154. =====================
  155. 4 09:34:Page 1-1
  156.  
  157.  num hunk         size filename         punit            type         base  alv     size
  158.    0 text          248 intui_hello4.o   intui_hello4.c   code            0    0      244
  159.                        LIB:sc.lib       dummy.c          code          244    0        4
  160.    1 __MERGED       5c intui_hello4.o   intui_hello4.c   data            0    0       50
  161.                        intui_hello4.o   intui_hello4.c   bss            50    0        c
  162.  
  163. 4 09:34:Page 3-1
  164.  
  165. symbol                   (Def) Module  Off
  166. _LinkerDB              (0:*)               intui_hello4.c          6
  167.  
  168. =====================
  169.  
  170. MUCH better!  As you can see, all symbols are now defined in intui_hello4.c except
  171. for one pulled in from dummy.c in sc.lib.  This symbol turns out to be the dummy
  172. version of __chkabort that gets pulled in because you specified the NOCHKABORT
  173. option.  It's only 4 bytes, and you're not going to do any better in your code,
  174. so there's no point in worrying about this one.  _LinkerDB is a linker-defined
  175. symbol used by the startup code to locate the beginning of external data, so
  176. there's nothing you can do about that one either.  This is as good as it will
  177. get without tinkering with the actual program's algorithm.
  178.  
  179.  
  180. -- 
  181.   *****                    / walker@unx.sas.com
  182.  *|_o_o|\\     Doug Walker<  BIX, Portal: djwalker
  183.  *|. o.| ||                \ CompuServe: 71165,2274
  184.   | o  |//     
  185.   ====== 
  186. Any opinions expressed are mine, not those of SAS Institute, Inc.
  187.